﻿using System;
using System.ComponentModel;
using System.Windows;

namespace TestRunner 
{
    /// <summary>
    /// Interaction logic for CountInputWindow.xaml
    /// </summary>
    public partial class CountInputWindow : INotifyPropertyChanged 
    {
        public UInt32 Count { get; set; }
        public string Line1Text { get; set; }
        public string Line2Text { get; set; }

        public CountInputWindow() 
        {
            InitializeComponent();
            DataContext = this;
            Loaded += CountInputWindow_Loaded;

        }

        void CountInputWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs("Line1Text"));
                handler(this, new PropertyChangedEventArgs("Line2Text"));
            }
            if (Count > 0)
            {
                textBox1.Text = Count.ToString();
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textBox1.Text)) return;

            uint value;
            if (!UInt32.TryParse(textBox1.Text, out value)) return;
            if (value <= 0) return;
            Count = value;
            DialogResult = true;
            Close();
            
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
